#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lc (o<<1)
#define rc (o<<1|1)
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=8e4+10;
int n,mp[MAXN],tot;
struct node
{
	int l,r,h;
	bool operator <(const node b)const
	{
		return h<b.h;
	}
}a[MAXN];
struct Seg_T
{
	LL sumv[MAXN*4];
	int addv[MAXN*4];
	void push_up(int o)
	{
		sumv[o]=sumv[lc]+sumv[rc];
		return;
	}
	void push_down(int o,int l,int r)
	{
		if(addv[o])
		{
			int mid=(l+r)>>1;
			sumv[lc]=(LL)(mp[mid]-mp[l])*addv[o];
			sumv[rc]=(LL)(mp[r]-mp[mid])*addv[o];
			addv[lc]=addv[rc]=addv[o];
			addv[o]=0;
		}
		return;
	}
	void update(int o,int l,int r,int yl,int yr,int k)
	{
		if(yl<=l&&r<=yr)
		{
			sumv[o]=(LL)(mp[r]-mp[l])*k;
			addv[o]=k;
			return;
		}
		int mid=(l+r)>>1;
		push_down(o,l,r);
		if(yl<mid)update(lc,l,mid,yl,yr,k);
		if(yr>mid)update(rc,mid,r,yl,yr,k);
		push_up(o);
		return;
	}
}T1;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	n=read();
	for(int i=1;i<=n;++i)
		mp[++tot]=a[i].l=read(),mp[++tot]=a[i].r=read(),a[i].h=read();
	sort(mp+1,mp+1+tot);
	tot=unique(mp+1,mp+1+tot)-mp-1;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i)
		T1.update(1,1,tot,lower_bound(mp+1,mp+1+tot,a[i].l)-mp,lower_bound(mp+1,mp+1+tot,a[i].r)-mp,a[i].h);
	printf("%lld\n",T1.sumv[1]);
	return 0;
}
